<template>
	<!-- 小程序使用 page-meta -->
	<!--#ifdef MP-->
	<page-meta :page-style="pageStyle"></page-meta>
	<!--#endif-->
	<view v-if="!successful">
		<view class="sys-head fixed">
			<view class="sys-bar" :style="{height:sysHeight}"></view>
			<!-- #ifdef MP || APP-PLUS -->
			<view class="sys-title">
				<view class='iconfont icon-ic_leftarrow' :style="{top:sysHeight}" @tap='goBack'></view>
				<text v-show="isFixed">商户入驻</text>
			</view>
			<!-- #endif -->
			<view v-if="isFixed" class="bg"></view>
		</view>
		<form report-submit='true'>
			<view class='merchantsSettled'>
				<view class="merchantBgCount">
					<image mode="widthFix" class="merchantBg" :src="domain+'/static/images/merchantBg.png'" alt="">
				</view>
				<view class="application-record" @click="jumpToList">
					申请记录
					<text class="iconfont icon-ic_rightarrow"></text>
				</view>
				<view class='list' style="height: 600px;overflow-y: auto;">
					<!--新增-->
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">注册手机号</text>
							<input type="number" placeholder="请输入注册手机号" v-model="merchantData.usr_phone"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">联系人姓名</text>
							<input type="text" placeholder="请输入联系人姓名" v-model="merchantData.cont_name"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">联系人手机号</text>
							<input type="number" placeholder="请输入联系人手机号" v-model="merchantData.cont_phone"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">电子邮箱</text>
							<input type="text" placeholder="请输入电子邮箱" v-model="merchantData.customer_email"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">商户名称</text>
							<input type="text" maxlength="30" placeholder="请输入商户名称" v-model="merchantData.mer_name"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
						<!-- 	 -->
						<text class="item-title" style="margin-top: 20rpx;">注：企业填全称 小微商户填负责人姓名</text>
					</view>
					<!-- <view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">营业执照名称</text>
							<input type="text" placeholder="请输入营业执照名称" v-model="merchantData.mer_name"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view> -->
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">商户简称</text>
							<input type="text" placeholder="请输入商户简称" v-model="merchantData.mer_short_name"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="uni-list">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db acea-row row-middle">
									<text class="item-name">商户类型</text>
									<picker @change="bindPickerChangeEntry" :value="entry_index" :range="entry_array"
										range-key="name">
										<input placeholder="请选择商户类型" type="text" readonly disabled
											v-model="entry_mer_type_name">
										<view class='iconfont icon-ic_rightarrow'></view>
									</picker>
								</view>
							</view>
						</view>
					</view>
					<view class="item" v-if="merchantData.entry_mer_type==1">
						<view class="acea-row row-middle">
							<text class="item-name">营业执照编号</text>
							<input type="text" placeholder="请输入营业执照编号" v-model="merchantData.license_code"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">注册地址</text>
							<input type="text" placeholder="请输入注册地址" v-model="merchantData.reg_addr"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">营业地址</text>
							<input type="text" placeholder="请输入营业地址" v-model="merchantData.cust_addr"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>

					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">商户电话</text>
							<input type="number" placeholder="请输入商户电话" v-model="merchantData.cust_tel"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">商户有效日期</text>
							<!-- mer_start_valid_date shrangestartDate开始  mer_valid_date shrangeendDate结束 -->


							<view class="example-body">
								<view class="picker-container">
									<text>开始时间</text>
									<uni-datetime-picker v-model="shrangestartDate" type="date" :border="false" />
								</view>
								<view class="picker-container">
									<text>结束时间</text>
									<uni-datetime-picker v-model="shrangeendDate" type="date"
										:start-date="shrangestartDate" :border="false" />
								</view>
								<!-- <uni-datetime-picker v-model="shrange" type="daterange" @maskClick="maskClick"
									:border="false" /> -->
							</view>
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">法人姓名</text>
							<input type="text" placeholder="请输入法人姓名" v-model="merchantData.legal_name"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">法人身份号</text>
							<input type="text" placeholder="请输入法人身份号" v-model="merchantData.legal_idno"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">法人电话</text>
							<input type="number" placeholder="请输入法人电话" v-model="merchantData.legal_mp"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">法人身份证地址</text>
							<input type="number" placeholder="请输入法人身份证地址" v-model="merchantData.egal_addr"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<!-- legal_start_cert_id_expires开始   legal_id_expires -->
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">身份证有效期</text>
							<view class="example-body">
								<view class="picker-container">
									<text>开始时间</text>
									<uni-datetime-picker v-model="sfzrangestartDate" type="date" :border="false" />
								</view>
								<view class="picker-container">
									<text>结束时间</text>
									<uni-datetime-picker v-model="sfzrangeendDate" type="date"
										:start-date="sfzrangestartDate" :border="false" />
								</view>
								<!-- <uni-datetime-picker v-model="sfzrange" type="daterange" @change="changeLog"
									:border="false" /> -->
							</view>
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">结算银行卡号</text>
							<input type="text" placeholder="请输入银行卡号" v-model="merchantData.card_id_mask"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">银行卡开户行</text>
							<uni-combox :candidates="bankNames" :border="false" @input="onBankSelect"
								placeholder="请选择开户行" v-model="bank_name">
							</uni-combox>
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">银行卡开户姓名</text>
							<input type="text" placeholder="请输入开户姓名" v-model="merchantData.card_name"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>

					<view class="item">
						<view class="uni-list">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db acea-row row-middle">
									<text class="item-name">银行卡类型</text>
									<picker @change="bindPickerChangeBank" :value="bank_index" :range="bank_array"
										range-key="name">
										<input placeholder="请选择银行卡类型" type="text" readonly disabled
											v-model="bank_acct_type_name">
										<view class='iconfont icon-ic_rightarrow'></view>
									</picker>
								</view>
							</view>
						</view>
					</view>
					<view class="item" v-if="merchantData.bank_acct_type==1">
						<view class="acea-row row-middle">
							<text class="item-name">经营范围</text>
							<input type="text" placeholder="经营范围" v-model="merchantData.business_scope"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">银行卡开户地</text>
							<view class="flex">
								<picker mode="selector" range-key="title" :range="provinces" @change="onProvinceChange">
									<view>{{ selectedProvince || '请选择省份' }}</view>
								</picker>
								<picker v-if="selectedProvince" mode="selector" range-key="title"
									:range="getCurrentCities" @change="onCityChange">
									<view>{{ selectedCity || '请选择城市' }}</view>
								</picker>
							</view>

						</view>
					</view>



					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">商户地址</text>
							<view class="region">
								<view class="region_count acea-row row-between-wrapper" @click="changeRegion">
									<text v-if="!addressInfo.length" style="color:#cdcdcd;">请选择地址</text>
									<text v-else class="line1 region-width">{{addressText}}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">码牌编码</text>
							<input type="text" placeholder="请输入码牌编码" v-model="merchantData.bianma" @input="validateBtn"
								placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">线上代理账号</text>
							<input type="text" placeholder="请输入线上代理账号" v-model="merchantData.zhanghao"
								@input="validateBtn" placeholder-class='placeholder' />
						</view>
					</view>
					<!--新增end-->

					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">用户姓名</text>
							<input type="text" placeholder="请输入姓名" v-model="merchantData.user_name" @input="validateBtn"
								placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item">
						<view class="acea-row row-middle">
							<text class="item-name">联系电话</text>
							<input type="number" placeholder="请输入手机号" v-model="merchantData.phone" @input="validateBtn"
								placeholder-class='placeholder' />
						</view>
					</view>
					<view class="item rel">
						<view class="acea-row row-middle">
							<text class="item-name">验证码</text>
							<input type="text" placeholder="填写验证码" v-model="merchantData.yanzhengma"
								@input="validateBtn" class="codeIput" placeholder-class='placeholder' />
							<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''"
								@click="handleVerify">
								{{ text }}
							</button>
						</view>
					</view>
					<!-- <view class="item" v-if="isShowCode">
						<view class="acea-row row-middle">
							<text class="item-name">验证码</text>
							<input type="text" placeholder="请输入验证码" class="codeIput" v-model="codeVal"
								@input="validateBtn" placeholder-class='placeholder' />
							<view class="imageCode" @click="again">
								<image :src="codeUrl" />
							</view>
						</view>
					</view> -->
					<view class="item">
						<view class="uni-list">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db acea-row row-middle">
									<text class="item-name">商户分类</text>
									<picker @change="bindPickerChange" :value="index" :range="array"
										range-key="category_name">
										<input placeholder="请选择商户分类" type="text" readonly disabled
											v-model="mer_classification">
										<view class='iconfont icon-ic_rightarrow'></view>
									</picker>
								</view>
							</view>
						</view>
					</view>
					<view class="item">
						<view class="uni-list">
							<view class="uni-list-cell">
								<view class="uni-list-cell-db acea-row row-middle">
									<view class="item-name acea-row row-middle">
										<text>店铺类型</text>
										<text class="iconfont icon-icon_question" @click="getAgreement"></text>
									</view>

									<picker @change="bindPickerChange1" :value="index1" :range="storeTypeArr"
										range-key="type_name">
										<input placeholder="请选择店铺类型" type="text" disabled readonly
											v-model="mer_storeType">
										<view v-if="mer_storeType" @tap.stop="mer_storeType=''"
											class="iconfont icon-guanbi2"></view>
										<view class='iconfont icon-ic_rightarrow'></view>
									</picker>
								</view>
							</view>
						</view>
					</view>
					<view class="item no-border">
						<view class='acea-row row-middle'>
							<text class="item-title">请上传营业执照照片、法人身份证正面、法人身份证反面、门店照片、银行账户信息照片/银行卡正面照片</text>
							<text class="item-desc">(图片最多可上传10张,图片格式支持JPG、PNG、JPEG)</text>
							<view class="upload">
								<view class='pictrue' v-for="(item,index) in pics" :key="index" :data-index="index"
									@click="getPhotoClickIdx">
									<image :src='item'></image>
									<text class='iconfont icon-ic_close2' @click.stop='DelPic(index)'></text>
								</view>
								<view class='pictrue acea-row row-center-wrapper row-column' @click='uploadpic'
									v-if="pics.length < 10">
									<text class='iconfont icon-ic_camera1'></text>
									<view>上传图片</view>
								</view>
							</view>
						</view>
					</view>

					<view class="item no-border acea-row row-middle">
						<checkbox-group @change='ChangeIsAgree'>
							<checkbox class="checkbox" :checked="isAgree ? true : false" />已阅读并同意
						</checkbox-group>
						<button class="settleAgree" @click="getConfig">《入驻协议》</button>
					</view>
					<button class='submitBtn' :class="validate === true ? 'on':''" @click="formSubmit">提交申请</button>
				</view>
			</view>
		</form>
		<areaWindow ref="areaWindow" :display="display" :address="addressInfo" @submit="OnChangeAddress"
			@changeClose="changeClose"></areaWindow>
		<view class="instructions" v-if="showProtocol">
			<view class="agreement-count">
				<view class="setAgCount">
					<view class="title">{{isType ? '店铺类型说明' : '商户入驻协议'}}</view>
					<view class="agBox">
						<view class="content">
							<jyf-parser :html="protocol" ref="article" :tag-style="tagStyle"></jyf-parser>
						</view>
					</view>
				</view>
				<text class="icon iconfont icon-ic_close1" @click="showProtocol = false"></text>
			</view>
		</view>
		<view class='loadingicon acea-row row-center-wrapper' v-if="loading">
			<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>
		</view>
		<Verify @success="success" @closeVerfiy="closeVerfiy" :imgSize="{ width: '330px', height: '155px' }"
			ref="verify"></Verify>
	</view>
	<view class="settledSuccessMain" v-else>
		<view class="settledSuccessful">
			<image class="image" src="../static/images/settledSuccessful.svg" alt="">
				<view class="success-text">
					<view class="title">恭喜，您的资料提交成功！</view>
					<view class="info">预计15个工作日内审核完毕，平台客服会及时与您联系！</view>
				</view>
				<view class="goHome" hover-class="none" @click="goHome">
					返回首页
				</view>
		</view>
	</view>
</template>
<script>
	// +----------------------------------------------------------------------
	// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
	// +----------------------------------------------------------------------
	// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
	// +----------------------------------------------------------------------
	// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
	// +----------------------------------------------------------------------
	// | Author: CRMEB Team <admin@crmeb.com>
	// +----------------------------------------------------------------------
	let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
	import {
		create,
		verify,
		merClassifly,
		getGoodsDetails,
		updateGoodsRecord,
		getStoreTypeApi
	} from '@/api/store.js';
	import {
		getCityV2,
		getCityList
	} from '@/api/api.js';
	import {
		getCaptcha,
		getAgreementApi
	} from "@/api/user";
	import {
		mapGetters
	} from "vuex";
	import {
		configMap
	} from "@/utils";
	import util from '@/utils/util.js';
	import parser from "@/components/jyf-parser/jyf-parser";
	import Verify from '@/components/verify/verify.vue';
	import areaWindow from '@/components/areaWindow';
	import addForm from './addform.json';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		HTTP_REQUEST_URL
	} from '@/config/app';
	import {
		bankCodes,
		findBankByCode,
		findBankByName
	} from './bankCodes.js';
	const app = getApp();
	export default {
		components: {
			"jyf-parser": parser,
			Verify,
			areaWindow
		},
		data() {
			return {
				sysHeight: sysHeight,
				domain: HTTP_REQUEST_URL,
				cartId: '', //购物车id
				pinkId: 0, //拼团id
				couponId: 0, //优惠券id
				text: "获取验证码",
				codeUrl: "",
				disabled: false,
				isAgree: false,
				showProtocol: false,
				isShowCode: false,
				loading: false,
				//
				merchantData: {
					enterprise_name: "",
					user_name: "",
					phone: "", //验证码
					classification: '', //商户分类
					bank_acct_type: '', //银行卡类型
					entry_mer_type: '', //商户类型
					bank_code: '',
				},
				validate: false,
				successful: false,
				keyCode: "",
				codeVal: "",
				protocol: this.sys_intention_agree,
				timer: "",
				index: 0,
				index1: 0,
				mer_classification: "",
				bank_acct_type_name: '', //结算银行账户类型
				bank_index: 0,
				shrange: [],
				shrangestartDate: '', //营业执照开始时间
				shrangeendDate: '', //营业执照结束时间
				sfzrange: [],
				sfzrangestartDate: '', //身份证开始时间
				sfzrangeendDate: '', //身份证结束时间
				bank_array: [{
					name: '对公',
					id: '1'
				}, {
					name: '对私',
					id: '2'
				}],
				entry_index: 0,
				entry_mer_type_name: '', //商户类型
				entry_array: [{
					name: '企业',
					id: '1'
				}, {
					name: '小微',
					id: '2'
				}],


				array: [{
					category_name: '',
					merchant_category_id: ''
				}],
				storeTypeArr: [{
					type_name: '',
					mer_type_id: ''
				}],
				mer_storeType: '',
				pics: [],
				tagStyle: {
					img: 'width:100%;display:block;'
				},
				mer_i_id: null, // 商户申请id
				isType: false,
				pageStyle: 'overflow: visible;', // 小程序页面样式
				isFixed: false,
				addressInfo: [],
				display: false,
				address_id: 0, //地址id
				//开户行列表
				bankArr: bankCodes.map(bank => bank.value),
				bankNames: bankCodes.map(bank => bank.label), // 只提取银行名称作为选项
				//开户行id
				bank_name: '',
				addressIdinfo: [],
				provinces: addForm,
				getCurrentCities: [],
				// this.cities = this.addressData[this.provinces[this.provinceIndex]];
				selectedProvince: '',
				selectedCity: '',
				 items: []
			};
		},
		beforeDestroy() {
			clearTimeout(this.timer)
		},
		// computed: configMap({sys_intention_agree:''},mapGetters(['isLogin','viewColor','keyColor'])),
		computed: {
			...mapGetters(['isLogin', 'viewColor']),
			addressText() {
				//console.log(this.addressInfo.map(v => v.id))
				let addressIds = this.addressInfo.map(v => v.id)
				this.merchantData.province_id = addressIds[0]
				this.merchantData.city_id = addressIds[1]
				this.merchantData.district_id = addressIds[2]
				//console.log(this.merchantData.province_id, this.merchantData.city_id, this.merchantData.district_id)
				return this.addressInfo.map(v => v.name).join('/');
			}
		},
		onLoad(options) {
			//console.log(this.provinces)
			if (this.isLogin) {
				this.getClassfication();
				this.getStoreType();
			} else {
				toLogin()
			}
			if (options.mer_i_id) {
				this.mer_i_id = options.mer_i_id
				uni.showLoading({
					title: '获取数据中',
				});
				this.$nextTick(function() {
					this.getGoodsDetails(options.mer_i_id)
				})
			}
			this.getUserAddress();
			this.getCityList();
		},
		watch: {
			//@confirm="onConfirm"

			shrangestartDate(newval) {
				let one = this.shrangestartDate
				this.merchantData.mer_start_valid_date = one.replace(/-/g, "");
				
			},
			shrangeendDate(newval) {
				let one = this.shrangeendDate
				this.merchantData.mer_valid_date = one.replace(/-/g, "");
				
			},
			sfzrangestartDate(newval) {
				let one = this.sfzrangestartDate
				this.merchantData.legal_start_cert_id_expires = one.replace(/-/g, "");
				
			},
			sfzrangeendDate(newval) {
				let one = this.sfzrangeendDate
				this.merchantData.legal_id_expires = one.replace(/-/g, "");
				
			},
			/* shrange(newval) {
				let one = this.shrange[0]
				let ones = this.shrange[1]
				this.merchantData.mer_start_valid_date = one.replace(/-/g, "");
				this.merchantData.mer_valid_date = ones.replace(/-/g, "");
			},
			sfzrange(newval) {
				let one = this.sfzrange[0]
				let ones = this.sfzrange[1]
				this.merchantData.legal_start_cert_id_expires = one.replace(/-/g, "");
				this.merchantData.legal_id_expires = ones.replace(/-/g, "");

			}, */
		},
		onShow() {
			
		},
		onReady() {},
		methods: {			
			onProvinceChange(e) {
				//console.log(this.provinces)
				const index = e.detail.value;
				this.selectedProvince = this.provinces[index].title;
				this.merchantData.prov_code = this.provinces[index].value;
				// this.getCurrentCities = this.provinces[this.provinces[this.provinceIndex]];
				const province = this.provinces[index];
				this.getCurrentCities = province ? province.cities : [];
				this.selectedCity = ''; // 重置城市选择
			},
			onCityChange(e) {
				const index = e.detail.value;
				const selectedProvince = this.provinces.find(p => p.title === this.selectedProvince);
				this.selectedCity = selectedProvince.cities[index].title;
				this.merchantData.area_code = selectedProvince.cities[index].value;
			},
			maskClick(e) {
				console.log('maskClick事件:', e);
			},
			maskClicks(e) {
				console.log('maskClick事件:', e);
			},
			changeLog(e) {
				console.log('change事件:', e);
			},
			changeLogs(e) {
				console.log('change事件:', e);
			},
			//地址
			OnChangeAddress(address) {
				this.addressInfo = address;
			},
			// 关闭地址弹窗；
			changeClose: function() {
				this.display = false;
			},
			changeRegion() {
				this.display = true;
			},
			onBankSelect(value) {
				// 根据选中的银行名称查找对应的银行代码
				const bank = bankCodes.find(item => item.label === value);
				if (bank) {
					this.merchantData.bank_code = bank.value;

				} else {
					this.merchantData.bank_code = '';
				}
			},
			// 地址数据
			getCityList: function() {
				let that = this;
				getCityV2(0).then(res => {
					this.district = res.data
					console.log("地址数据", res)
				})
			},
			getUserAddress: function() {
				if (!this.address_id) return false;
				let that = this;
				getAddressDetail(this.address_id).then(res => {
					let region = [res.data.province, res.data.city, res.data.district];
					that.$set(that, 'userAddress', res.data);
					that.$set(that, 'region', region);
					that.city_id = res.data.city_id
					that.addressInfo = res.data.area
					console.log("地址数据选择数据", res)
					console.log(that.addressInfo.map(v => v.name).join('/'))
				});
			},
			//
			goBack: function() {
				uni.navigateBack();
			},
			getConfig() {
				this.isType = false;
				this.showProtocol = true;
				// 获取配置
				this.protocol = this.sys_intention_agree
			},
			/*获取发票说明*/
			getAgreement() {
				let that = this
				that.showProtocol = true;
				that.isType = true
				getAgreementApi('sys_merchant_type').then(res => {
					that.protocol = res.data.sys_merchant_type
				})
			},
			// 获取历史提交数据详情
			getGoodsDetails(id) {
				getGoodsDetails(id).then(res => {
					console.log(res.data)
					let arr = Object.keys(this.merchantData)
					let resData = res.data
					arr.map(item => {
						this.merchantData.enterprise_name = resData.mer_name
						this.merchantData.user_name = resData.name

						this.merchantData.phone = resData.phone
						this.merchantData.classification = resData.merchant_category_id
						this.merchantData.mer_type = resData.mer_type_id
						//新增
						this.merchantData.bank_acct_type = resData.bank_acct_type
						this.merchantData.bank_code = resData.bank_code
						this.merchantData.bianma = resData.bianma
						this.merchantData.card_id_mask = resData.card_id_mask
						this.merchantData.card_name = resData.card_name
						//this.merchantData.classification = resData.classification
						this.merchantData.cont_phone = resData.cont_phone
						this.merchantData.cont_name = resData.cont_name
						this.merchantData.cust_addr = resData.cust_addr
						this.merchantData.cust_tel = resData.cust_tel
						this.merchantData.customer_email = resData.customer_email
						//this.merchantData.enterprise_name = resData.enterprise_name
						this.merchantData.entry_mer_type = resData.entry_mer_type
						this.merchantData.legal_idno = resData.legal_idno
						this.merchantData.legal_mp = resData.legal_mp
						this.merchantData.legal_name = resData.legal_name
						this.merchantData.license_code = resData.license_code
						this.merchantData.mer_name = resData.mer_name
						this.merchantData.mer_short_name = resData.mer_short_name
						//this.merchantData.mer_type = resData.mer_type
						this.merchantData.reg_addr = resData.reg_addr
						//this.merchantData.user_name = resData.user_name
						this.merchantData.usr_phone = resData.usr_phone
						this.merchantData.yanzhengma = resData.yanzhengma
						this.merchantData.zhanghao = resData.zhanghao
						this.merchantData.business_scope = resData.business_scope
					})
					this.pics = resData.images
					this.mer_classification = this.getCategoryName(resData.merchant_category_id, this.array)
					this.mer_storeType = this.getStoreTypeName(resData.mer_type_id, this.storeTypeArr)
					this.bank_acct_type_name = this.getBankName(resData.bank_acct_type, this.bank_array)
					this.entry_mer_type_name = this.getCategoryTypeName(resData.entry_mer_type, this.entry_array)
					let time1 = this.getDataTime(resData.mer_start_valid_date)
					let time2 = this.getDataTime(resData.mer_valid_date)
					this.shrange = [time1, time2]
					let time3 = this.getDataTime(resData.legal_start_cert_id_expires)
					let time4 = this.getDataTime(resData.legal_id_expires)
					this.sfzrange = [time3, time4]
					let dataVal = resData.prov_code
					let datavalc = resData.area_code
					// console.log(resData.prov_code + resData.area_code,resData.area_code，'银行查找')
					this.bank_name = this.getBankFontname(resData.bank_code)
					let porDatas = this.provinces
					let porlist = porDatas.find(item => item.value === dataVal)
					console.log(porlist, '测试')
					this.selectedProvince = porlist.title
					let cityList = porlist.cities
					let cityLists = cityList.find(item => item.value === datavalc)
					this.selectedCity = cityLists.title
					//selectedProvince,selectedCity

					uni.hideLoading();
				})
			},
			//获取开户行
			getBankFontname(id) {
				console.log(id)
				const bank = bankCodes.find(item => item.value === id);
				console.log(bank.label)
				return bank.label
			},
			//修改日期
			getDataTime(time) {
				if (!/^\d{8}$/.test(time)) {
					throw new Error('日期格式必须为 YYYYMMDD');
				}

				const year = time.substring(0, 4);
				const month = time.substring(4, 6);
				const day = time.substring(6, 8);

				return `${year}-${month}-${day}`;
			},
			//获取银行类型
			getBankName(ids, arr) {
				for (let i = 0; i < arr.length; i++) {
					if (arr[i].id == ids) {
						return arr[i]['name']
					}

				}
			},
			//获取商户类型
			getCategoryTypeName(id, arr) {
				console.log(id, arr)
				for (let i = 0; i < arr.length; i++) {
					if (arr[i].id == id) {
						console.log(arr[i]['name'])
						return arr[i]['name']
					}

				}
			},
			//获取商户分类名称
			getCategoryName(id, arr) {
				for (let i = 0; i < arr.length; i++) {
					if (arr[i].merchant_category_id === id) {
						return arr[i]['category_name']
					}
				}
			},
			//获取店铺类型名称
			getStoreTypeName(id, arr) {
				for (let i = 0; i < arr.length; i++) {
					if (arr[i].mer_type_id === id) {
						return arr[i]['type_name']
					}
				}
			},
			bindPickerChangeEntry: function(e) {
				this.entry_index = e.target.value
				let idx = e.target.value
				this.merchantData.entry_mer_type = this.entry_array[idx]['id']
				this.entry_mer_type_name = this.entry_array[idx]['name']
				this.validateBtn()
			},
			bindPickerChangeBank: function(e) {
				this.bank_index = e.target.value
				let idx = e.target.value
				this.merchantData.bank_acct_type = this.bank_array[idx]['id']
				this.bank_acct_type_name = this.bank_array[idx]['name']
				this.validateBtn()
			},
			bindPickerChange: function(e) {
				this.index = e.target.value
				let idx = e.target.value
				this.merchantData.classification = this.array[idx]['merchant_category_id']
				this.mer_classification = this.array[idx]['category_name']
				this.validateBtn()
			},
			bindPickerChange1: function(e) {
				this.index1 = e.target.value
				let idx = e.target.value
				this.merchantData.mer_type = this.storeTypeArr[idx]['mer_type_id']
				this.mer_storeType = this.storeTypeArr[idx]['type_name']
				this.validateBtn()
			},
			// 获取商户分类
			getClassfication: function() {
				merClassifly()
					.then(res => {
						this.array = res.data
					})
					.catch(res => {
						this.$util.Tips({
							title: res
						});
					});
			},
			// 获取店铺类型
			getStoreType: function() {
				getStoreTypeApi()
					.then(res => {
						this.storeTypeArr = res.data
					})
					.catch(res => {
						this.$util.Tips({
							title: res
						});
					});
			},
			// 图片预览
			// 获得相册 idx
			e(e) {
				console.log('点击了',)
				let _this = this;
				let idx = e.currentTarget.dataset.index;
				_this.imgPreview(_this.pics, idx);
			},
			// 图片预览
			imgPreview: function(list, idx) {
				// list：图片 url 数组
				if (list && list.length > 0) {
					uni.previewImage({
						current: list[idx], //  传 Number H5端出现不兼容
						urls: list
					});
				}
			},
			toggleTab(str) {
				this.$refs[str].show();
			},
			// 首页
			goHome() {
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
			again() {
				this.getcaptcha()
			},
			/**
			 * 上传文件
			 *
			 */
			uploadpic: function() {
				console.log('上传文件')
				let that = this;
				util.uploadImageOne('upload/certificate', function(res) {
					that.pics.push(res.data.path);
					that.$set(that, 'pics', that.pics);
				});
			},
			/**
			 * 删除图片
			 *
			 */
			DelPic: function(index) {
				let that = this,
					pic = this.pics[index];
				that.pics.splice(index, 1);
				that.$set(that, 'pics', that.pics);
			},
			getCode() {
				let that = this
				getCodeApi()
					.then(res => {
						that.keyCode = res.data.key;
					})
					.catch(res => {
						that.$util.Tips({
							title: res
						});
					});
			},
			async code(data) {
				let that = this;
				if (!that.merchantData.phone) return that.$util.Tips({
					title: '请填写手机号码'
				});
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.merchantData.phone)) return that.$util.Tips({
					title: '请输入正确的手机号码'
				});
				await verify({
						phone: that.merchantData.phone,
						// key: that.codeKey,
						// code: that.codeVal,
						type: 'intention',
						//captchaVerification: data.captchaVerification
					})
					.then(res => {
						that.$util.Tips({
							title: res.message
						});
						that.sendCode();
					})
					.catch(res => {
						that.$util.Tips({
							title: res
						});
						if (res.status == 402) {
							// that.getcaptcha();
						}
					});
			},
			getcaptcha() {
				let that = this
				getCaptcha().then(data => {
					that.codeUrl = data.data.captcha; //图片路径
					that.codeVal = data.data.code; //图片验证码
					that.codeKey = data.data.key //图片验证码key
				})
				that.isShowCode = true;
			},
			sendCode() {
				if (this.disabled) return;
				this.disabled = true;
				let n = 60;
				this.text = "剩余 " + n + "s";
				const run = setInterval(() => {
					n = n - 1;
					if (n < 0) {
						clearInterval(run);
					}
					this.text = "剩余 " + n + "s";
					if (this.text < "剩余 " + 0 + "s") {
						this.disabled = false;
						this.text = "重新获取";
					}
				}, 1000);
			},
			onConfirm(val) {
				this.region = val.checkArr[0] + '-' + val.checkArr[1] + '-' + val.checkArr[2];
			},
			ChangeIsAgree: function(e) {
				this.isAgree = !this.isAgree;
				this.validateBtn();
			},
			formSubmit: function(e) {
				let that = this;
				if (that.validateForm() && that.validate) {
					let requestData = {
						phone: that.merchantData.phone, //联系电话
						mer_name: that.merchantData.enterprise_name, //商户名称
						name: that.merchantData.user_name, //联系人电话
						code: that.merchantData.yanzhengma, //验证码
						merchant_category_id: that.merchantData.classification, //
						mer_type_id: that.merchantData.mer_type,
						images: that.pics,
						bank_acct_type: that.merchantData.bank_acct_type,
						bank_code: that.merchantData.bank_code,
						bianma: that.merchantData.bianma,
						card_id_mask: that.merchantData.card_id_mask,
						card_name: that.merchantData.card_name,
						classification: that.merchantData.classification,
						cont_phone: that.merchantData.cont_phone,
						cont_name: that.merchantData.cont_name,
						cust_addr: that.merchantData.cust_addr,
						cust_tel: that.merchantData.cust_tel,
						customer_email: that.merchantData.customer_email,
						enterprise_name: that.merchantData.enterprise_name,
						entry_mer_type: that.merchantData.entry_mer_type,
						legal_idno: that.merchantData.legal_idno,
						legal_mp: that.merchantData.legal_mp,
						legal_name: that.merchantData.legal_name,
						license_code: that.merchantData.license_code,
						mer_name: that.merchantData.mer_name,
						mer_short_name: that.merchantData.mer_short_name,
						mer_type: that.merchantData.mer_type,
						reg_addr: that.merchantData.reg_addr,
						user_name: that.merchantData.user_name,
						usr_phone: that.merchantData.usr_phone,
						yanzhengma: that.merchantData.yanzhengma,
						zhanghao: that.merchantData.zhanghao,
						prov_code: that.merchantData.prov_code,
						area_code: that.merchantData.area_code,
						province_id: that.merchantData.province_id,
						city_id: that.merchantData.city_id,
						district_id: that.merchantData.district_id,
						mer_start_valid_date: that.merchantData.mer_start_valid_date,
						mer_valid_date: that.merchantData.mer_valid_date,
						legal_start_cert_id_expires: that.merchantData.legal_start_cert_id_expires,
						legal_id_expires: that.merchantData.legal_id_expires,
						business_scope:that.merchantData.business_scope
					}
					that.validate = false;
					if (that.mer_i_id) {
						updateGoodsRecord(that.mer_i_id, requestData).then(res => {
							if (res.status == 200) {
								title: '提交成功',
								that.loading = true;
								that.timer = setTimeout(() => {
									that.successful = true;
									that.validate = true;
								}, 1000)
							}
						}).catch(res => {
							that.validate = true;
							that.$util.Tips({
								title: res
							});
						})
					} else {
						//提交表单  this.merchantData
						create(requestData).then(data => {
							if (data.status == 200) {
								title: '提交成功',
								that.loading = true;
								this.timer = setTimeout(() => {
									that.successful = true;
									that.validate = true;
								}, 1000)
							}

						}).catch(res => {
							that.validate = true;
							that.$util.Tips({
								title: res
							});
						})
					}
				}
			},
			validateBtn: function() {
				let that = this,
					value = that.merchantData;
				

				if (value.mer_name && value.user_name && value.phone && /^1(3|4|5|7|8|9|6)\d{9}$/i.test(value
						.phone) &&
					value.yanzhengma && that.isAgree && value.classification) {
					if (!that.isShowCode) {
						that.validate = true;
					} else {
						if (that.codeVal) {
							that.validate = true;
						} else {
							that.validate = false;
						}
					}
				} else {
					that.validate = false;
				}
			},
			validateForm: function() {
				let that = this,
					value = that.merchantData;
				if (!value.mer_name) return that.$util.Tips({
					title: '请输入企业名称'
				});
				if (!value.user_name) return that.$util.Tips({
					title: '请输入姓名'
				});
				if (value.entry_mer_type == 1) {
					if (!value.license_code) return that.$util.Tips({
						title: '请输入营业执照编码'
					});
				}
				if (!value.phone) return that.$util.Tips({
					title: '请输入手机号'
				});
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(value.phone)) return that.$util.Tips({
					title: '请输入正确的手机号码'
				});
				if (!value.yanzhengma) return that.$util.Tips({
					title: '请填写验证码'
				});
				if (!value.classification) return that.$util.Tips({
					title: '请选择商户分类'
				});
				if (!that.isAgree) return that.$util.Tips({
					title: '请勾选并同意入驻协议'
				});
				if (that.isShowCode && !that.codeVal) return that.$util.Tips({
					title: '请填写图片验证码'
				});
				that.validate = true;
				return true;
			},
			jumpToList() {
				uni.navigateTo({
					url: "/pages/store/applicationRecord/index"
				})
			},
			success(data) {
				this.$refs.verify.hide();
				this.code(data);
				this.pageStyle = 'overflow: visible;'; // 小程序
			},
			closeVerfiy() {
				this.pageStyle = 'overflow: visible;'; // 小程序
			},
			handleVerify() {
				if (!this.merchantData.phone) return this.$util.Tips({
					title: '请输入手机号'
				});
				if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(this.merchantData.phone)) return this.$util.Tips({
					title: '请输入正确的手机号码'
				});
				if (!this.isAgree) return this.$util.Tips({
					title: '请勾选并同意入驻协议'
				});
				//xiaochegn
			this.code();
			//this.$refs.verify.show();
				this.pageStyle = 'overflow: hidden;'; // 小程序
			}
		},
		// 滚动监听
		/* onPageScroll(e) {
			this.isFixed = e.scrollTop > 160;
		}, */
	}
</script>

<style scoped lang="scss">
	/deep/checkbox .uni-checkbox-input.uni-checkbox-input-checked,
	/deep/checkbox .wx-checkbox-input.wx-checkbox-input-checked {
		border: 1px solid #E93323 !important;
		background-color: #E93323 !important;
		color: #fff !important;
		border-radius: 100%;
	}

	.sys-head .bg {
		background: #E93323;
	}

	.uni-input-placeholder {
		color: #B2B2B2;
	}

	.item-name {
		width: 190rpx;
	}

	.uni-list-cell {
		position: relative;

		.icon-ic_rightarrow {
			font-size: 14px;
			color: #7a7a7a;
			position: absolute;
			right: 0;
			top: 7rpx;
		}

		.icon-guanbi2 {
			right: 35px;
		}
	}

	.merchantBgCount {
		line-height: 0;
	}

	.merchantsSettled {
		background: linear-gradient(180deg, #FE7015 0%, #EB3B26 100%);
		min-height: 100vh;
		padding-bottom: 70rpx;
	}

	.merchantsSettled .merchantBg {
		width: 750rpx;
		width: 100%;
	}

	.merchantsSettled .list {
		background-color: #fff;
		border-radius: 12px;
		padding: 10rpx 0 22px;
		margin: 0 15px;
	}

	.application-record {
		position: absolute;
		display: flex;
		align-items: center;
		top: 240rpx;
		right: 0;
		color: #FFDDB8;
		font-size: 22rpx;
		background-color: rgba(0, 0, 0, 0.15);
		padding: 8rpx 18rpx;
		border-radius: 20px 0px 0px 20px;
	}

	.merchantsSettled .list .item {
		padding: 50rpx 0 20rpx;
		position: relative;
		margin: 0 20px;

		&.no-border {
			border-bottom: none;
			padding-left: 0;
			padding-right: 0;
		}

		.item-title {
			color: #666666;
			font-size: 28rpx;
			display: block;
		}

		.item-desc {
			color: #B2B2B2;
			font-size: 22rpx;
			display: block;
			margin-top: 9rpx;
			line-height: 36rpx;
		}
	}

	.acea-row,
	.upload {
		display: -webkit-box;
		display: -moz-box;
		display: -webkit-flex;
		display: -ms-flexbox;
		display: flex;
		-webkit-box-lines: multiple;
		-moz-box-lines: multiple;
		-o-box-lines: multiple;
		-webkit-flex-wrap: wrap;
		-ms-flex-wrap: wrap;
		flex-wrap: wrap;
	}

	.upload {
		margin-top: 20rpx;
	}

	.merchantsSettled .list .item .pictrue {
		width: 130rpx;
		height: 130rpx;
		margin: 24rpx 22rpx 0 0;
		position: relative;
		font-size: 22rpx;
		color: #bbb;
		border-radius: 16rpx;

		&:nth-child(4n) {
			margin-right: 0;
		}

		&:nth-last-child(1) {
			border: 1rpx dashed #ccc;
			box-sizing: border-box;
			background: #f5f5f5;
		}

		uni-image,
		image {
			width: 100%;
			height: 100%;
			border-radius: 16rpx;

			img {
				-webkit-touch-callout: none;
				-webkit-user-select: none;
				-moz-user-select: none;
				display: block;
				position: absolute;
				top: 0;
				left: 0;
				opacity: 0;
				width: 100%;
				height: 100%;
			}
		}

		.icon-ic_camera1 {
			font-size: 50rpx;
			margin-bottom: 10rpx;
		}

		.icon-ic_close2 {
			font-size: 36rpx;
			position: absolute;
			top: -10px;
			right: -10px;
		}
	}

	.uni-list-cell-db {
		position: relative;
	}

	.icon-icon_question {
		font-size: 28rpx;
		color: #D8D8D8;
		margin-left: 8rpx;
		position: relative;
		top: 2rpx;
	}

	.merchantsSettled .list .item .imageCode {
		position: absolute;
		top: 7px;
		right: 0;
	}

	.merchantsSettled .list .item .icon {
		font-size: 40rpx;
		color: #b4b1b4;
	}

	.merchantsSettled .list .item input {
		width: 400rpx;
		font-size: 30rpx;
	}

	.merchantsSettled .list .item .placeholder {
		color: #b2b2b2;
	}

	.merchantsSettled .default {
		padding: 0 30rpx;
		height: 90rpx;
		background-color: #fff;
		margin-top: 23rpx;
	}

	.merchantsSettled .default checkbox {
		margin-right: 15rpx;
	}

	.merchantsSettled .acea-row uni-image {
		width: 20px;
		height: 20px;
		display: block;
	}

	.merchantsSettled .list .item .codeIput {
		width: 125px;
	}

	.uni-input-input {
		display: block;
		height: 100%;
		background: none;
		color: inherit;
		opacity: 1;
		-webkit-text-fill-color: currentcolor;
		font: inherit;
		line-height: inherit;
		letter-spacing: inherit;
		text-align: inherit;
		text-indent: inherit;
		text-transform: inherit;
		text-shadow: inherit;
	}

	.merchantsSettled .list .item .code {
		position: absolute;
		width: 89px;
		line-height: 26px;
		border: 1px solid #E93323;
		border-radius: 200rpx;
		color: #E93323;
		text-align: center;
		bottom: 8px;
		right: 0;
		font-size: 23rpx;
	}

	.merchantsSettled .list .item .code.on {
		background-color: #bbb;
		color: #fff;
		border-color: #bbb;
	}

	.merchantsSettled .submitBtn {
		width: 588rpx;
		margin: 0 auto;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		font-size: 28rpx;
		color: #fff;
		background: #bbbbbb;
		margin-top: 50rpx;
		pointer-events: none;
	}

	.merchantsSettled .submitBtn.on {
		background: #E93323;
		pointer-events: all;
	}

	uni-checkbox-group,
	.settleAgree {
		display: inline-block;
		font-size: 24rpx;
	}

	uni-checkbox-group {
		color: #999;
		font-size: 24rpx;
	}

	/deep/ uni-checkbox .uni-checkbox-input,
	/deep/ wx-checkbox .wx-checkbox-input {
		border-radius: 100%;
		width: 32rpx;
		height: 32rpx;
	}

	.settleAgree {
		color: #E93323;
		margin-left: 6rpx;
	}

	.merchantsSettled uni-checkbox .uni-checkbox-wrapper {
		width: 30rpx;
		height: 30rpx;
		border: 2rpx solid #C3C3C3;
		border-radius: 15px;
	}

	.settledSuccessMain {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #fff;
	}

	.settledSuccessful {
		flex: 1;
		width: 100%;
		padding: 0 64rpx;
		height: auto;
		background: #fff;
		text-align: center;
	}

	.settledSuccessful .success-text {
		padding: 32rpx 26rpx;
		margin-top: 70px;
	}

	.settledSuccessful .image {
		width: 380rpx;
		height: 314rpx;
		margin-top: 132rpx;
	}

	.settledSuccessful .title {
		color: #333333;
		font-size: 32rpx;
		font-weight: bold;

	}

	.settledSuccessful .info {
		color: #A0A0A0;
		font-size: 26rpx;
		margin-top: 24rpx;
	}

	.settledSuccessful .goHome {
		margin: 120rpx auto 0;
		line-height: 86rpx;
		color: #282828;
		font-size: 28rpx;
		border: 1px solid #B4B4B4;
		border-radius: 200px;
	}

	/deep/ uni-checkbox .uni-checkbox-input {
		width: 30rpx;
		height: 30rpx;
		position: relative;
	}

	/deep/ uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before {
		font-size: 28rpx;
	}

	.loadingicon {
		height: 100vh;
		overflow: hidden;
		position: absolute;
		top: 0;
		left: 0;
	}

	.icon-ic_rightarrow {
		font-size: 22rpx;
	}

	checkbox-group {
		display: inline-block;
		color: #999;
		font-size: 24rpx;
	}

	.setAgCount {
		/deep/ table {
			border: 1px solid #DDD;
			border-bottom: none;
			border-right: none;
		}

		/deep/ td,
		th {
			padding: 5rpx 10rpx;
			border-bottom: 1px solid #DDD;
			border-right: 1px solid #DDD;
		}
	}

	.picker-container {
		display: flex;
		align-items: center;
		color: #666;
	}
</style>